/**
 * Copyright (C) 2013 AirChina
 *
 * @description:
 * @version:v1.0.0
 */
package com.china.api.wechat.processor.main;

import java.util.Date;
import java.util.List;

import com.china.api.wechat.processor.model.PictureMessage;



/**
 * @Description:
 * @author:larry
 * @Created:2013-10-29上午11:06:05
 */
public class PictureResponse extends Response {
	
	private List<PictureMessage> data;

	public PictureResponse(String userId, List<PictureMessage> data) {
		setUserId(userId);
		this.data = data;
	}

	@Override
	public String toXML() {
		Long l = new Date().getTime();
		StringBuilder sb = new StringBuilder();
		int size = data.size();
		sb.append("<xml>");
		sb.append("<ToUserName><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></ToUserName>");
		sb.append("<FromUserName><![CDATA[");
		sb.append(getMyid());
		sb.append("]]></FromUserName>");
		sb.append("<CreateTime>");
		sb.append(l);
		sb.append("</CreateTime>");
		sb.append("<MsgType><![CDATA[news]]></MsgType>");
		sb.append("<ArticleCount>");
		sb.append(size);
		sb.append("</ArticleCount>");
		sb.append("<Articles>");
		for (PictureMessage msg : data) {
			sb.append("<item>");
			sb.append("<Title><![CDATA[").append(msg.getTitle()).append("]]></Title>");
			sb.append("<Description><![CDATA[").append(msg.getDescription()).append("]]></Description>");
			sb.append("<PicUrl><![CDATA[").append(msg.getPicUrl()).append("]]></PicUrl>");
			sb.append("<Url><![CDATA[").append(msg.getHref()).append("]]></Url>");
			sb.append("</item>");
		}
		sb.append("</Articles>" + "<FuncFlag>1</FuncFlag>");
		sb.append("</xml>");
		return sb.toString();
	}

	public List<PictureMessage> getData() {
		return data;
	}
}
